package pers.course.week5;

import java.util.Scanner;

public class UFOs {
    public static int letterToNumber(char ch) {
        int num = 0;
        num = (int)(ch - 'A' + 1);
        return num;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String comet = in.nextLine();
            String group = in.nextLine();
            char[] comet_array = comet.toCharArray();
            int comet_sum = 1;
            char[] group_array = group.toCharArray();
            int group_sum = 1;
            for (int i = 0; i < comet.length(); i++) comet_sum *= letterToNumber(comet_array[i]);
            for (int i = 0; i < group.length(); i++) group_sum *= letterToNumber(group_array[i]);
            if ((comet_sum % 47) == (group_sum % 47)) {
                System.out.println("GO");
            } else {
                System.out.println("STAY");
            }
        }
        in.close();
    }
}
